package com.wenhuitec.android.tang.sysui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wenhuitec.android.tang.R;
import com.wenhuitec.android.tang.sysui.adapter.PickAdapter;
import com.wenhuitec.android.tang.sysui.model.PickModel;

import java.util.ArrayList;
import java.util.List;

public class PickView extends LinearLayout {

    private TextView titleTv;
    private PickAdapter pickAdapter;
    private Context mContext;
    private RecyclerView recyclerView;


    public PickView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater.from(context).inflate(R.layout.view_pick, this, true);
        mContext = context;
        titleTv = findViewById(R.id.title);
        recyclerView = findViewById(R.id.recyclerView);
        pickAdapter = new PickAdapter(mContext);
    }

    public void setTitle(String title) {
        titleTv.setText(title);
    }

    public void setSelectPot(int pot) {
        pickAdapter.setSelected(pot);
    }

    public void setSelectNoClick(int pot) {
        pickAdapter.setSelectedNoClick(pot);
    }

    public void setRv(List<PickModel> pickModelList) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(RecyclerView.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(pickAdapter);
        pickAdapter.setPickModelList(pickModelList);
        pickAdapter.notifyDataSetChanged();
    }

    public void setOnClick(PickAdapter.PickOnClick pickOnClick) {
        pickAdapter.setmPickOnClick(pickOnClick);
    }
}
